package com.siwei.mes.entity.erp;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.validator.AddGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.List;


/**
 * ERP任务单打印记录(RwdextraPrintRecord)实体类
 *
 * @author linzi
 * @since 2024-08-31 23:39:06
 */
@Data
@Accessors(chain = true)
@Table(name = "pk_rwdextra_print_record")
@ApiModel(value = "RwdextraPrintRecord", description = "ERP任务单打印记录")
public class RwdextraPrintRecord implements Serializable {
    private static final long serialVersionUID = 985952253788702173L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "ERP任务单打印记录主键ID", name = "id")
    private Long id;
    /**
     * 任务单号
     */
    @Column(name = "frwdh")
    @ApiModelProperty(value = "任务单id rwdextra表中的frwdh", name = "frwdh")
    private Integer frwdh;
    /**
     * 打印人
     */
    @Column(name = "print_user_id")
    @ApiModelProperty(value = "打印人", name = "printUserId")
    private Long printUserId;
    /**
     * 打印时间
     */
    @Column(name = "print_time")
    @ApiModelProperty(value = "打印时间", name = "printTime")
    private Date printTime;
    /**
     * 打印数据来源json
     */
    @Column(name = "print_json")
    @ApiModelProperty(value = "打印数据来源json", name = "printJson")
    private JSONObject printJson;
    /**
     * 打印范围
     */
    @Column(name = "print_html")
    @ApiModelProperty(value = "打印范围", name = "printHtml")
    private String printHtml;

    @Transient
    @ApiModelProperty(value = "打印人名称")
    private String printUserName;

    @Transient
    @ApiModelProperty(value = "多个任务单")
    @NotNull(groups = {AddGroup.class}, message = "任务单号集合为空")
    private List<Integer> frwdhList;

    @Transient
    @ApiModelProperty(value = "打印数据来源json", name = "printJson")
    private JSONArray printJsonList;

    public RwdextraPrintRecord init(boolean isCreate) {
        if (isCreate) {
            this.setPrintUserId(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null).setPrintTime(new Date());
        }
        return this;
    }
}
